import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
  // 状态管理 
  state: {
    user: function (){
      const data = localStorage.getItem('user')
      if (data==="undefined"||data==null){
        return []
      }
      return data
    }
  },
  // 数据调配
  mutations: {
    setUser (state, item) {
      state.user = item
    }
  },
  actions: {},
  modules: {}
})
store.subscribe((mutations, state) => {
  localStorage.setItem('user', state.user)

})
export default store
